// pages/contact/contact.ts
const app = getApp<IAppOption>()
const RADIUS = 4;
const INIT_MARKER = {
    callout: {
        content: '家校共育云',
        padding: 10,
        borderRadius: 2,
        display: 'ALWAYS'
    },
    latitude: 31.546486,
    longitude: 120.305020,
    iconPath: '../../images/Marker1_Activated@3x.png',
    width: '34px',
    height: '34px',
    rotate: 0,
    alpha: 1
};
const INIT_CALLOUT = {
    content: '家校共育云',
    padding: 12,
    display: 'ALWAYS',
    fontSize: 14,
    textAlign: 'center',
    borderRadius: RADIUS,
    borderWidth: 2,
    bgColor: '#ffffff'
};
const INIT_CALLOUT_MARKER = {
    callout: { ...INIT_CALLOUT },
    latitude: 31.546486,
    longitude: 120.305020,

};
Page({

    /**
     * 页面的初始数据
     */
    data: {
        config: {},
        apiUrl: app.globalData.apiUrl,
        scale: 15,
        markers: [{
            ...INIT_MARKER
        }],
        calloutMarkers: [{
            ...INIT_CALLOUT_MARKER
        }],
        location: {
            latitude: 31.546486,
            longitude: 120.305020,
        },
        localLocation: {
            latitude: '',
            longitude: '',
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad() {
        let that = this
        wx.getLocation({
            type: 'wgs84',
            success(res) {
                that.setData({
                    'localLocation.latitude': res.latitude,
                    'localLocation.longitude': res.longitude
                })
            }
        })
        this.getConfigDetail(1)
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        if (typeof this.getTabBar === 'function' &&
            this.getTabBar()) {
            this.getTabBar().setData({
                selected: 3
            })
        }
    },
    markertap() {
        let that = this
        wx.openLocation({
            latitude: Number(that.data.location.latitude),
            longitude: Number(that.data.location.longitude),
            name: '家校共育云',
            address: '家校共育云'
        })
    },
    callKefu() {
        wx.makePhoneCall({
            phoneNumber: app.globalData.mobile
        })
    },
    showWechat(e: any) {
        wx.previewImage({
            current: e.currentTarget.dataset.wechat, // 当前显示图片的 http 链接
            urls: [e.currentTarget.dataset.wechat] // 需要预览的图片 http 链接列表
        })
    },
    getConfigDetail(id: number) {
        let that = this;
        wx.request({
            url: app.globalData.apiUrl + 'api/config/' + id + '/detail',
            success: function (res: any) {
                if (res.data.code == 0) {
                    that.setData({
                        config: res.data.data
                    })
                }
            }
        })
    },
    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})
export default app